package com.struts.web.homepage;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.lg.system.CLGAction;
import com.lg.system.CSqlMap;
import com.ibatis.po.system.TNews;
import com.struts.deal.homepage.Deal;

public class HomePageAction extends CLGAction {
	public ActionForward execute(ActionMapping actionMapping,
			ActionForm actionForm,
			HttpServletRequest request,
			HttpServletResponse response) throws
			Exception {
		HomePageForm aWebForm = (HomePageForm)actionForm;
		Deal.doDefaultSearchVocation(request, response, aWebForm);
		SqlMapClient sqlmap=CSqlMap.getSqlMapConfig();
		List hopNewsList = null;//0最新动态
		List onlineCorporList = null;//4网上企业招聘
		List lawList = null;//3法律法规
		List mediaList = null;//2传媒博览
		List strategyList = null;//1职场攻略
		List onsiteCorporList = null;//5现场招聘
		List hopSearchList = null;//6热门搜索
		List qzzxList = null;//7求职之星
		TNews tnews = new TNews();

		try{
			//��ȡ������Ϣ
			tnews.setKindOfNewsId("0");
			hopNewsList=sqlmap.queryForList("T_NEWS.selectByNewsSort",tnews);
			if(hopNewsList!=null){
				for(int i=0;i<hopNewsList.size();i++){
					TNews tn = (TNews)hopNewsList.get(i);
					String str = tn.getTitle();
					if(str.length()>35){
						tn.setTitle(str.substring(0, 34)+"...");
						hopNewsList.set(i, tn);
					}
				}
				request.setAttribute("hopnewslist", hopNewsList);
			}
			
			//走马灯
			String zouMaDengContent = "";
			zouMaDengContent = (String)sqlmap.queryForObject("T_NEWS.selectZouMaDeng");
			aWebForm.setZouMaDeng(zouMaDengContent);

			tnews.setKindOfNewsId("1");
			strategyList=sqlmap.queryForList("T_NEWS.selectByNewsSort",tnews);
			if(strategyList!=null)
			{
				for(int i=0;i<strategyList.size();i++){
					TNews tn = (TNews)strategyList.get(i);
					String str = tn.getTitle();
					if(str.length()>20){
						tn.setTitle(str.substring(0, 19)+"...");
						strategyList.set(i, tn);
					}
				}
				request.setAttribute("strategylist", strategyList);
			}

			tnews.setKindOfNewsId("2");
			mediaList=sqlmap.queryForList("T_NEWS.selectByNewsSort",tnews);
			if(mediaList!=null){
				for(int i=0;i<mediaList.size();i++){
					TNews tn = (TNews)mediaList.get(i);
					String str = tn.getTitle();
					if(str.length()>20){
						tn.setTitle(str.substring(0, 19)+"...");
						mediaList.set(i, tn);
					}
				}
				request.setAttribute("medialist", mediaList);
			}

			tnews.setKindOfNewsId("3");
			lawList=sqlmap.queryForList("T_NEWS.selectByNewsSort",tnews);
			if(lawList!=null)
			{
				for(int i=0;i<lawList.size();i++){
					TNews tn = (TNews)lawList.get(i);
					String str = tn.getTitle();
					if(str.length()>20){
						tn.setTitle(str.substring(0, 19)+"...");
						lawList.set(i, tn);
					}
				}
				request.setAttribute("lawlist", lawList);
			}

			//4企业推荐

			onlineCorporList=sqlmap.queryForList("T_CORPORATION.selectRecommend");
			if(onlineCorporList!=null)request.setAttribute("onlinecorporlist", onlineCorporList);
            //5现场招聘
			tnews.setKindOfNewsId("5");
			onsiteCorporList=sqlmap.queryForList("T_NEWS.selectByNewsSort",tnews);
			if(onsiteCorporList!=null)
			{
				for(int i=0;i<onsiteCorporList.size();i++){
					TNews tn = (TNews)onsiteCorporList.get(i);
					String str = tn.getTitle();
					if(str.length()>20){
						tn.setTitle(str.substring(0, 19)+"...");
						onsiteCorporList.set(i, tn);
					}
				}
				request.setAttribute("onsiteCorporList", onsiteCorporList);
			}
			
			//6热门搜索��ȡ���������б���
//			hopSearchList = sqlmap.queryForList("T_HOP_SEARCH.selectWithSort");
//			if(hopSearchList!=null)request.setAttribute("hopsearchlist", hopSearchList);

			//7求职之星
			qzzxList = sqlmap.queryForList("T_USER_INFO.selectQZZX");
			if(qzzxList != null)request.setAttribute("qzzxlist", qzzxList);
		}catch(Exception e){
			e.printStackTrace();
		}


		return actionMapping.findForward("index");

	}
}
